/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package action;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Query;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import pojo.ActivityHistory;
/**
 *
 * @author Mostafa
 */
public class DatelogAction extends org.apache.struts.action.Action {

  
    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception 
    {
        String activitydate=request.getParameter("date");
        if(activitydate!=null&& !activitydate.equals(""))
        {
            String operator=request.getParameter("operator");
            Query query=new Query();
            DateFormat df=new SimpleDateFormat("dd/mm/yyyy");
            Date d=df.parse(activitydate);
            StringBuffer result=new StringBuffer();
            Vector<ActivityHistory> pactivities= query.getByDate(getDataSource(request,"MyDS").getConnection(),new java.sql.Date(d.getTime()),operator);
                result.append(" <table border=\"1\">  <tr> <td> Admin-Name </td> <td> Activity-Name </td> <td> Activity-Time </td> <td> Activity-Description </td> <td> Status </td><td> Provider-Name </td> </tr>");
            for (int i = 0; i < pactivities.size(); i++) 
            {
                result.append("<tr> <td> "+pactivities.get(i).getAdminName()+" </td> <td> "+pactivities.get(i).getActivityName()+" </td>"
                    + " <td>"+pactivities.get(i).getActivityTime()+" </td> <td>"+pactivities.get(i).getActivities().getDescription()+" </td> <td> "+pactivities.get(i).getStatus()+" </td> <td> "+pactivities.get(i).getProviderName()+" </td>  </tr>");
            }
            result.append("</table>");
            response.getWriter().println(result.toString());
        }
        else
            response.getWriter().println("No Support Date");
        return null;
    }
}
